package com.j1ay.forum.controller;

import com.j1ay.forum.service.AnswerService;
import com.j1ay.forum.model.dto.params.AnswerParam;
import com.j1ay.forum.model.pojo.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author J1ay
 * @Date 2021/12/17 16:08
 * @Description
 */
@RestController
@RequestMapping("api/answer")
@Api(value="Answer Controller",tags={"回答类接口"})
public class AnswerController {

    @Autowired(required = false)
    private AnswerService answerService;

    @ApiOperation(value = "根据问题Id查看问题详情")
    @GetMapping("detail/{questionId}")
    public Result findQuestionById(@PathVariable("questionId") Long questionId) {
        return answerService.findAnswersById(questionId);
    }

    @ApiOperation(value = "点赞该回答")
    @PostMapping("praise/{answerId}")
    public Result toPraiseQuestion(@PathVariable("answerId") Long answerId) {
        return answerService.toPraiseAnswer(answerId);
    }

    @ApiOperation(value = "根据用户id获取他的回帖列表")
    @PostMapping("my/{username}")
    public Result getUserAnswer(@PathVariable("username") String username){
        return answerService.getUserAnswer(username);
    }

    @ApiOperation(value = "回帖")
    @PostMapping("reply")
    public Result replyForQuestion(@RequestBody AnswerParam answerParam) {
        return answerService.replyForQuestion(answerParam);
    }

    @ApiOperation(value = "删帖")
    @DeleteMapping("delete/{id}")
    public Result deleteAnswer(@PathVariable("id") Long id) {
        return answerService.deleteAnswer(id);
    }
}
